#include "monitor.h"
#include "stm32f10x_conf.h"

void Time3_GPIO_Init()
 {
    GPIO_InitTypeDef GPIO_InitStructure;
		
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
	 
    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA,&GPIO_InitStructure);
		
    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
    GPIO_Init(GPIOB,&GPIO_InitStructure);
 }
void Tim3_Init(u16 arr,u16 psc)
{
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    TIM_OCInitTypeDef TIM_OCInitStructure;
		
		Time3_GPIO_Init();
		
    TIM_TimeBaseStructure.TIM_Period=arr;
    TIM_TimeBaseStructure.TIM_Prescaler=psc;
    TIM_TimeBaseStructure.TIM_ClockDivision=0x00;
    TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
    //TIM_TimeBaseStructure.TIM_RepetitionCounter=0x00;
    TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
  
    TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
    //TIM_OCInitStructure.TIM_Pulse=1000;
    TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
    TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
    TIM_OC1Init(TIM3,&TIM_OCInitStructure);    
 
  
    //TIM_OCInitStructure.TIM_Pulse=400;
    TIM_OC2Init(TIM3,&TIM_OCInitStructure);   
   
    //TIM_OCInitStructure.TIM_Pulse=1000;
    TIM_OC3Init(TIM3,&TIM_OCInitStructure); 
  
    //TIM_OCInitStructure.TIM_Pulse=550;

    TIM_OC4Init(TIM3,&TIM_OCInitStructure);   

		TIM_Cmd(TIM3,ENABLE);
		//TIM_CtrlPWMOutputs(TIM3,ENABLE);
}
void SetCCR2(u16 ccr1,u16 ccr2,u16 ccr3,u16 ccr4)
{
	//TIM_SetCompare2(TIM3,ccr);
	TIM3->CCR1=ccr1;
	TIM3->CCR1=ccr2;
	TIM3->CCR1=ccr3;
	TIM3->CCR1=ccr4;
	
}
